// pages/refund/refund.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        status: {
            1: "售后待审核",
            2: "售后处理中",
            3: "售后已完成",
            4: "售后已关闭"
        },
        sign: 'refund',
        is_show:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.get_storage();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    get_storage: function () {
        var that = this;
        var sign = that.data.sign;
        wx.getStorage({
            key: 'memberInfo',
            success: function (res) {
                var data = res.data;
                var member_id = data.id;
                var open_id = data.open_id;
                that.setData({
                    member_id: member_id,
                    open_id: open_id
                })
                if (sign == "customer_server") {
                    that.order_list(member_id);
                } else if (sign == "refund") {
                    that.refund_order(member_id);
                }
            }
        })
        
        
    },//售后
    order_list: function (member_id) {
        var that = this;
        var params = {};
        params['id'] = member_id;
        wx.request({
            url: app.config() + "member/memberAfterSaleOrder",
            data: params,
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if (res.data.status==0){
                    var data = res.data.data;
                    var len=data.length;
                    for (var i = 0; i < len; i++) {
                        data[i].status = that.data.status[data[i].status];
                        data[i]['after_sale_create_time'] = app.to_time(data[i].after_sale_create_time)
                    }
                    if(len){
                        that.setData({
                            order_list: data,
                            is_show:false
                        })
                    }else{
                        that.setData({
                            order_list: data,
                            is_show:true
                        })
                    }
                    
                }
            }
        })
    },//售后详情
    to_customer_service_details(e) {
        var goods_id = e.currentTarget.dataset.goods_id;
        wx.navigateTo({
            url: '../../pages/customerServiceOrderDetails/customerServiceOrderDetails?goods_id=' + goods_id
        })
    },//退款订单
    refund_order: function (member_id) {
        var that = this;
        var params = {};
        params['id'] = member_id;
        params['mall_status'] = 4;
        wx.request({
            url: app.config() + "member/memberOrder",
            data: params,
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.status==0){
                    var data=res.data.data;
                    var len=res.data.data.length;
                    if(len){
                        that.setData({
                            refund_list: data,
                            len: len,
                            is_show:false
                        })
                    }else{
                        that.setData({
                            refund_list: data,
                            len: len,
                            is_show: true
                        })
                    }
                    
                }
            }
        })
    },//切换菜单
    switch_tab: function (e) {
        var that = this;
        var member_id=that.data.member_id;
        var sign = e.currentTarget.dataset.sign;
        that.setData({
            sign: sign
        })
        if(sign=="customer_server"){
            that.order_list(member_id)
        }else if(sign=="refund"){
            that.refund_order(member_id);
        }
    },
    refund_service_details:function(e){
        var goods_id = e.currentTarget.dataset.goods_id;
        wx.navigateTo({
            url: '../../pages/wattingReceiptOrderInfo/wattingReceiptOrderInfo?order_id=' + goods_id
        })
    }
})